package com.evil.kingdom.pojo.entity.person.base;

import cn.hutool.core.bean.BeanUtil;
import com.evil.kingdom.pojo.dto.person.base.PersonDto;
import com.evil.kingdom.pojo.entity.base.Fight;
import com.evil.kingdom.pojo.entity.base.Level;
import com.evil.common.mongo.entity.SingleName;
import com.evil.kingdom.pojo.enums.PersonTypeEnum;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

/**
 * 人物
 *
 * @author liyang
 * @date 2024-05-17 16:00
 */
@Getter
@Setter
@Document
public class Person extends Fight implements Level, SingleName {

    /**
     * 名称
     */
    @Id
    @NotBlank(message = "名称不能为空")
    private String name;

    /**
     * 年龄
     */
    @NotNull(message = "年龄不能为空")
    private Integer age;

    /**
     * 等级
     */
    private Integer level;

    /**
     * 经验值
     */
    private Integer experience;

    /**
     * 武器
     */
    private String arm;

    /**
     * 物品
     */
    private String item;

    /**
     * 坐骑
     */
    private String mount;

    /**
     * 人物类型
     */
    private Integer type;

    public Person() {
        super();
        this.level = 1;
        this.experience = 1;
        this.type = PersonTypeEnum.KING.getType();
    }

    public Person(String name, Integer age) {
        super();
        this.name = name;
        this.age = age;
        this.level = 1;
        this.experience = 1;
        this.type = PersonTypeEnum.KING.getType();
    }

    public Person(PersonDto dto) {
        super();
        BeanUtil.copyProperties(dto, this);
    }

    @Override
    public String getEntityName() {
        return "人物";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Person person = (Person) o;

        return name.equals(person.name);
    }

    @Override
    public int hashCode() {
        return name.hashCode();
    }

    @Override
    public String toString() {
        return name;
    }
}
